<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //预解析案例
        // 案例1
        /* var num = 10;
        fun();
        function fun(){
            console.log(num);
            var num = 20;
        } */
        //相当于执行了以下操作
        var num;
        function fun(){
            var num;
            console.log(num);
            num = 20;
        }
        num = 10;
        fun();
        // 案例2
        /* var num1 = 10;
        function fn(){
            console.log(num1);
            var num1 = 20;
            console.log(num1);
        }
        fn(); */
        //相当于执行了以下代码
        var num1;
        function fn(){
            var num1;
            console.log(num1);
            num1 = 20;
            console.log(num1);
        }
        num1 = 10;
        fn();
        //案例3
        /* var a = 18;
        f1();
        function f1(){
            var b = 9;
            console.log(a);
            console.log(b);
            var a = '123';
        } */
        //相当于执行了以下代码
        /* var a;
        function f1(){
            var b;
            var a;
            b = 9;
            console.log(a);
            console.log(b);
            a = '123';
        }
        a = 18;
        f1(); */
        //案例4
        /* f2();
        console.log(c);
        console.log(b);
        console.log(a);
        function f2(){
            var a = b = c = 9;
            console.log(a);
            console.log(b);
            console.log(c);
        } */
        //相当于执行了以下代码
        function f2(){
            var a;
            a = b = c = 9;
            //相当于 var a = 9; b = 9; c = 9; b 和 c 直接赋值 没有var 声明 当 全局变量
            //集体声明 var a = 9; b = 9; c = 9;
            console.log(a);
            console.log(b);
            console.log(c);
        }
        f2();
        console.log(c);
        console.log(b);
        console.log(a);
    </script>
</head>
<body>
    
</body>
</html>